<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增充值服务')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-UserCardRecharge-add">
            <input name="deptId" id="deptId"  type="hidden" />
            <input name="userId" id="userId"  type="hidden" />
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">用户：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input name="nickname" id="nickname" class="form-control" type="text" required autocomplete="off">
                        <div class="input-group-btn">
                            <button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown">
                                <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu dropdown-menu-right" role="menu">
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">门店：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input class="form-control" type="text" name="deptName" onclick="selectDeptTree()" id="treeName" required>
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">充值卡名称：</label>
                <div class="col-sm-8">
                    <input name="name" class="form-control" type="text" required>
                </div>
            </div>
            <!--<div class="form-group">
                <label class="col-sm-3 control-label is-required">剩余金额：</label>
                <div class="col-sm-8">
                    <input name="money" class="form-control" type="text" required>
                </div>
            </div>-->
            <div class="form-group">    
                <label class="col-sm-3 control-label">总金额：</label>
                <div class="col-sm-8">
                    <input name="countMoney" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">启用状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('sys_yes_no')}">
                        <input type="radio" th:id="${'status_' + dict.dictCode}" name="status" th:value="${dict.dictValue}" th:checked="${dict.default}" required>
                        <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <!--<div class="form-group">
                <label class="col-sm-3 control-label is-required">服务项目ID：</label>
                <div class="col-sm-8">
                    <input name="recycleTypeId" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">服务项目：</label>
                <div class="col-sm-8">
                    <select name="recycleType" class="form-control m-b" required>
                        <option value="">所有</option>
                    </select>
                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 代码生成请选择字典属性</span>
                </div>
            </div>-->
        </form>
    </div>
    <div class="row">
        <div class="col-sm-offset-5 col-sm-10">
            <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-suggest-js" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: select2-js" />

    <script th:inline="javascript">
        var prefix = ctx + "system/UserCardRecharge"
        $("#form-UserCardRecharge-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                var userId = $("#nickname").attr("data-id");
                $("#userId").val(userId);
                $.operate.saveTab(prefix + "/add", $('#form-UserCardRecharge-add').serialize());
            }
        }


        var users = [[${users}]];
        if(typeof users =="string"){
            users = eval(users);
        }

        var values=[];
        for(var index in users){
            var val = {};
            val.userId = users[index].id;
            val.nickname = users[index].nickname;
           var realname = "-";
            if(users[index].nickname){
               realname = users[index].nickname+"-";
            }
            if(users[index].realname){
              realname += users[index].realname;
            }
            if(realname != "-"){
                val.realname = realname;
                values.push(val);
            }
        }
        //data 数据中获取
        $("#nickname").bsSuggest({
            idField: "userId",
            keyField: "realname",
            data: {
                'value': values,
                'defaults': 'http://www.baidu.vip'
            }
        });

        /* 用户管理-修改-选择部门树 */
        function selectDeptTree() {
        	var deptId = $.common.isEmpty($("#deptId").val()) ? "100" : $("#deptId").val();
            var url = ctx + "system/dept/selectDeptTree/" + deptId;
		    var options = {
				title: '选择门店',
				width: "380",
				url: url,
				callBack: doSubmit
			};
			$.modal.openOptions(options);
		}
        function doSubmit(index, layero){
            var body = layer.getChildFrame('body', index);
            var deptId = body.find('#treeId').val();
            $("#deptId").val(deptId);
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
        }
    </script>
</body>
</html>